#!/usr/bin/env python

## @example multithread_auto.py
#  @see multithread_auto.c

import time

from fulguro import *


### BENCH PROCEDURES #########################################################
def benchmark(nbiter,function,*args):
    t=time.time()
    for i in range(nbiter):
        function(*args)
    t2=time.time()
    return ((t2-t)*1000)/nbiter
##############################################################################




imin = flgr2d_load_pgm("../../images/gray/cameraman.pgm")
imout1 = FLGR_Data2D(imin)
imout2 = FLGR_Data2D(imin)
nhb = FLGR_Data2D(3,3,1,imin.type,FLGR_RECT,FLGR_8_CONNEX)

#flgr2d_thread_function_data2d_data2d_nhb(FLGR2D_MEDIAN,imout1,imin,nhb,4)
speed = benchmark(10000,flgr2d_thread_function_data2d_data2d_nhb,CB_FLGR2D_MEDIAN,imout1,imin,nhb,2)
print "Automatic Multithread median time :",speed,"ms"

#flgr2d_median(imout1,imin,nhb)
speed = benchmark(10000,flgr2d_median,imout2,imin,nhb)
print "No thread Median time :",speed,"ms"


flgr_display(imout1, imout2, imin, "out_multithread", "out_nothread", "in")

